package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.Result;
import com.sky.service.OrderAdminService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrdersController")
@RequestMapping("/admin/order")
@Api("管理端订单相关接口")
public class OrdersController {
    @Autowired
    OrderAdminService orderAdminService;



    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result OrderPage(OrdersPageQueryDTO ordersPageQueryDTO){
        OrderVO orderVO = orderAdminService.OrderPage(ordersPageQueryDTO);
        return Result.success(orderVO);
    }

    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result queryStatistics(){
        OrderStatisticsVO orderStatisticsVO = orderAdminService.queryStatistics();
        return Result.success(orderStatisticsVO);
    }

    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderAdminService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result completeOrder(@PathVariable Long id){
        orderAdminService.completeOrder(id);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation("拒绝订单")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO rejectionDTO){
        orderAdminService.rejectionOrder(rejectionDTO);
        return Result.success();
    }

    @PutMapping("/confirm")
    @ApiOperation("接受订单")
    public Result confirmOrder(@RequestBody OrderVO orderVO){
        orderAdminService.confirmOrder(orderVO.getId());
        return Result.success();
    }

    @PutMapping("/delivery/{id}")
    @ApiOperation("派送订单")
    public Result deliveryOrder(@PathVariable Integer id){
            orderAdminService.deliveryOrder(id);
        return Result.success();
    }
}
